﻿namespace LeetCodeProject._0001_1000._001_100._007;

public class Solution
{
    public int Reverse(int x)
    {
        var n = 0;
        try
        {
            while (x != 0)
            {
                var d = x % 10;
                checked
                {
                    n = n * 10 + d;
                    x /= 10;
                }
            }
        }
        catch (OverflowException)
        {
            return 0;
        }

        return n;
    }
}